import axios from 'axios'
import {getLocalStorage} from './localStorage.js'
import { Toast } from 'mint-ui'
/**
 * 封装post请求
 * @param url
 * @param data
 * @returns {Promise}
 */
export function post (url, data = {}, config) {
  return new Promise((resolve, reject) => {
    data.token = getLocalStorage('fireToken')
    axios.post(url, data, config).then(
      response => {
        if (response.data.status !== '0') {
          Toast(response.data.tips)
        }
        resolve(response.data)
      },
      err => {
        reject(err)
      })
  })
}

/**
 * 封装get方法
 * @param url
 * @param data
 * @returns {Promise}
 */
export function get (url, params = {}, mode) {
  return new Promise((resolve, reject) => {
    params.token = getLocalStorage('fireToken')
    axios.get(url, {
      params: params
    })
      .then(response => {
        resolve(response.data)
      })
      .catch(err => {
        reject(err)
      })
  })
}
